home *** CD-ROM | disk | FTP | other *** search
- Path: grimsel.zurich.ibm.com!usenet
- From: wgk@zurich.ibm.com (Keith Whittingham)
- Newsgroups: comp.lang.c++
- Subject: Re: Null Pointer Assignment error
- Date: 6 Apr 1996 12:47:07 GMT
- Organization: IBM Research, ZRH
- Message-ID: <4k5p4b$tds@grimsel.zurich.ibm.com>
- References: <4k5g19$84a@newsgate.dircon.co.uk>
- Reply-To: wgk@zurich.ibm.com
- NNTP-Posting-Host: pine.zurich.ibm.com
- X-Newsreader: IBM NewsReader/2 v1.00
-
- In <4k5g19$84a@newsgate.dircon.co.uk>, dalim2@dircon.co.uk (Keith George) writes:
- >I get a Null pointer Assignment Error 'What is it?'
- >
- >I'm using Turbo C++ 3.0 to test a String class that I am trying to
- >understand copied from an "Understanding C++" book!
- >
- >The Turbo C++ help pages seem very brief!
- >
- >How can I track down this error ?
- >Why does it not happen in the large memory model?
- >
- >many regards
- > keith george
-
-
- You've assigned something to a NULL pointer:
-
- int *ptr;
-
- main()
- {
- *ptr = 1234;
- }
-
- ptr is a pointer to an integer and does not (in the example) have any memory
- to store anything in it. The way it's been defined assigns the value
- zero to this pointer (under most compilers (sic)). The line of code
- then writes the value 1234 to the address pointed to by ptr - e.g. 0.
-
- The compiler checks this by keeping a checksum of the first 32 bytes or
- so of memory at offset 0 in the data segment. If these are corrupted
- (they should never change) then it is reported to you at the end of
- the program run.
-
- Unfortunatly this check cannot be done in the large mode as 0x000:0x0000
- in the Intel architecture is the interrupt table and is subject to change
- during program runs.
-
- You need to be very careful when using pointers as Borland can only check
- for bad pointer assignement when the pointer has a value of 0.
-
- Borland debugger has a "breakpoint on changed memory global" option which
- if you set it to look at 0 for 16 odd bytes it will find the erroneous
- line of code - the program runs slowly though.
-
- Keith
-
-
-
-